package sse.ustc.cc.activity;



import sse.ustc.cc.fragment.AddCourseFrag;
import sse.ustc.cc.fragment.ChoosedCourseFrag;
import sse.ustc.cc.fragment.LeadCourseFrag;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

/**
 * 我的课程activity
 * 初始化添加课程、已选课程、导入课程fragment
 * @author xuhao
 *
 */
public class CourseAty extends FragmentActivity {
	
	//定义FragmentTabHost对象  
    private FragmentTabHost mTabHost;  
      
    //定义一个布局  
    private LayoutInflater layoutInflater;  
          
    //定义数组来存放Fragment界面  
    private Class fragmentArray[] = {AddCourseFrag.class,ChoosedCourseFrag.class,LeadCourseFrag.class};  
      
    //Tab选项卡的文字  
    private String mTextviewArray[] = {"添加课程", "已选课程", "导入课程"};
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);// 无标题
		setContentView(R.layout.mycourse);
		Intent intent=getIntent();  
        String result=intent.getStringExtra("addcourse"); 
       
		initView();
//		if(result.equals("add")){
//			mTabHost.setCurrentTab(0);
//		}
	}
	
	/** 
     * 初始化组件 
     */  
    private void initView(){  
        //实例化布局对象  
        layoutInflater = LayoutInflater.from(this);  
                  
        //实例化TabHost对象，得到TabHost  
        mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);  
        mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);   
          
        //得到fragment的个数  
        int count = fragmentArray.length;     
                  
        for(int i = 0; i < count; i++){    
            //为每一个Tab按钮设置图标、文字和内容  
            TabSpec tabSpec = mTabHost.newTabSpec(mTextviewArray[i]).setIndicator(getTabItemView(i));  
            //将Tab按钮添加进Tab选项卡中  
            mTabHost.addTab(tabSpec, fragmentArray[i], null);  
        }  
        
    }  
                  
    /** 
     * 给Tab按钮设置图标和文字 
     */  
    private View getTabItemView(int index){  
        View view = layoutInflater.inflate(R.layout.tab_item_view, null);  
          
        TextView textView = (TextView) view.findViewById(R.id.textview);          
        textView.setText(mTextviewArray[index]);  
      
        return view;  
    }
    
}
